/**********************************************************************
 *                                                                    *
 * tgt - Tiny Graphics Toolbox                                        *
 *                                                                    *
 * Copyright (C) 2006-2008 Visualization and Computer Graphics Group, *
 * Department of Computer Science, University of Muenster, Germany.   *
 * <http://viscg.uni-muenster.de>                                     *
 *                                                                    *
 * This file is part of the tgt library. This library is free         *
 * software; you can redistribute it and/or modify it under the terms *
 * of the GNU Lesser General Public License version 2.1 as published  *
 * by the Free Software Foundation.                                   *
 *                                                                    *
 * This library is distributed in the hope that it will be useful,    *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the       *
 * GNU Lesser General Public License for more details.                *
 *                                                                    *
 * You should have received a copy of the GNU Lesser General Public   *
 * License in the file "LICENSE.txt" along with this library.         *
 * If not, see <http://www.gnu.org/licenses/>.                        *
 *                                                                    *
 **********************************************************************/

#include "tgt/guiapplication.h"
#include "tgt/quadric.h"
#include "tgt/toolkitfactory.h"
#include "tgt/painter.h"
#include "tgt/camera.h"

using namespace tgt;

class MyPainter : public Painter {
public:
    virtual void paint();
    virtual void sizeChanged(const ivec2& size);
    virtual void init();
};

void MyPainter::paint() {
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	getCamera()->look();

    glColor3f(1.f, 0.f, 0.f);

    Sphere sphere(1.f, 64, 32);
    sphere.render();
}

void MyPainter::sizeChanged(const ivec2& size) {
    glViewport(0, 0, size.x, size.y);
}

void MyPainter::init() {
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    getCamera()->setPosition(vec3(0.f,0.f,4.f));
}

int main(int argc, char** argv) {
    std::cout
        << "tgt Sample Program: minimal" << std::endl
        << std::endl
        << "A minimal example displaying a simple red sphere on black ground to show how tgt" << std::endl
        << "is used." << std::endl
        << std::endl;

    // build a tgt app with the desired gui toolkit
    GUIApplication* tgtApp = ToolkitFactory::createApplication(argc, argv);

    GLCanvas* canvas = ToolkitFactory::createCanvas("tgt Example: Minimal");
    tgtApp->addCanvas(canvas);

    tgtApp->init();

    Camera camera;
    canvas->setCamera(&camera);
    MyPainter painter;
    canvas->setPainter(&painter);

    tgtApp->run();

    delete canvas;
    delete tgtApp;

    return 0;
}
